$(function(){
	//判断默认选中的按钮，并设置默认手续费
	if($('input[name="corpPayBankCode"]').length>0&&$('input[name="corpPayBankCode"]').is(':checked')){
		setViewFee($("#corpBankPound"),$("#orderFeeAmt"));	
	//}else if($('input[name="perBankPound"]').length>0&&$('input[name="perBankPound"]').is(':checked')){
	}else if($('input[name="personalPayBankCode"]').length>0&&$('input[name="personalPayBankCode"]').is(':checked')){
		setViewFee($("#perBankPound"),$("#orderFeeAmt"));	
	}else if($('input[name="yesAvalPay"]').length>0&&$('input[name="yesAvalPay"]').is(':checked')){
		setViewFee($("#acctPound"),$("#orderFeeAmt"));	
	}
	
	
	$('input[name="bankPayChannel"]').click(function(){
        $("#payChannel").val($(this).val());
		if($(this).val()=="01"){
			$("#corpBankList").hide();
			$("#personalBankList").show();
			$('input[name="corpPayBankCode"]').removeAttr("checked");
			//临时发现bug:如果选择网银支付，应该将余额支付的勾去掉
			if($('input[name="yesAvalPay"]').length>0){
				$('input[name="yesAvalPay"]').removeAttr("checked");
			}
            $("#payChannel").val("01");
			$("#i_b_c_0").prop("checked", true);
			
			//动态修改手续费
			setViewFee($("#perBankPound"),$("#orderFeeAmt"));
			
		}else{
            $("#payChannel").val("51");
			$("#corpBankList").show();
			$("#personalBankList").hide();
			$('input[name="personalPayBankCode"]').removeAttr("checked");
			$("#e_b_c_0").prop("checked", true);
			
			setViewFee($("#corpBankPound"),$("#orderFeeAmt"));
		}
		
	});
	
	
	$("#allPersonBanksDialog").dialog({
		autoOpen: false,
		modal: true,
		resizable: false,
		title: '选择银行',
		width:840,
		height:595,
		close:function(){
            $("#payChannel").val("01");
            $("#i_b_c_0").prop("checked", true);
			payInMoneyPwdCtl("1");
		}
	});
	
	$("#allCorpBanksDialog").dialog({
		autoOpen: false,
		modal: true,
		resizable: false,
		title: '选择银行',
		width:840,
		height:595,
		close:function(){
            $("#payChannel").val("51");
            $("#e_b_c_0").prop("checked", true);
			payInMoneyPwdCtl("1");
		}
	});

    $(':button').removeAttr("disabled");
});

var onLineBankShow = function(){
	var userType = $("#defalutPayUserType").val();
	if(('01' == userType) && pbankNum>0){
		$("#personalBank").prop("checked", true);
		$("#i_b_c_0").prop("checked", true);
		$("#corpBankList").hide();
		$("#personalBankList").show();
        $("#payChannel").val("01");
	}else if(('02' == userType )&& ebankNum>0){
		$("#corpBank").prop("checked", true);
		$("#e_b_c_0").prop("checked", true);
		$("#corpBankList").show();
		$("#personalBankList").hide();
        $("#payChannel").val("51");
	}
    if($("#yesAvalPay").length>0 && $("#payWay").val() =="A"){
        $("#payChannel").val("");
        $("#personalBank").removeAttr("checked");
        $("#corpBank").removeAttr("checked");
        $("#i_b_c_0").removeAttr("checked");
        $("#e_b_c_0").removeAttr("checked");
    }
};

var bankSel = function(bankImgId,label){
	$(label).parent().parent().parent().find("label").removeClass("cur");
	$(label).prop("class","cur");
	$("#"+bankImgId).prop("checked", true);
	if(bankImgId){
		if(bankImgId.substring(0,1)=="e" || bankImgId.substring(0,3)=="a_e"){
			$("#corpBank").prop("checked", true);
            $("#payChannel").val("51");
		}
		if(bankImgId.substring(0,1)=="i" || bankImgId.substring(0,3)=="a_i"){
			$("#personalBank").prop("checked", true);
            $("#payChannel").val("01");
		}
	}
    avalPayCheckInit();
};
function avalPayCheckInit(){
    if($("#yesAvalPay").length>0) {
        $("#yesAvalPay").removeAttr("checked");
    }
    if($('input:checkbox[name="noAvalPay"]').is(":checked")){
        $("#payWay").val("S");
        $("#exPayWay").val("S");
    }else{
        $("#payWay").val("F");
        $("#exPayWay").val("F");
    }
}

var showAllBanks = function(type){
	payInMoneyPwdCtl("0");
	if(type=="01"){
		$("#allPersonBanksDialog").dialog("open");
		$("#a_i_b_c_0").prop("checked", true);
	}else if(type=="51"){
		$("#allCorpBanksDialog").dialog("open");
		$("#a_e_b_c_0").prop("checked", true);
	}
};
//入金时，当弹出更多银行时，密码控件会遮挡
var payInMoneyPwdCtl = function(flag){
	var payInMoneyPasswordDiv = $("#payInMoneyPasswordDiv");
	if(payInMoneyPasswordDiv){
		if(flag=="0"){
			payInMoneyPasswordDiv.hide();
		}else{
			payInMoneyPasswordDiv.show();
		}
	}
};

var bankPaySubmit = function(btnId){
    var bankSelType = btnId.substring(btnId.length-1,btnId.length);
    if(bankSelType == '3' || bankSelType == '4'){
        var allCode;
        if(bankSelType == '3') allCode = $('input[name="personalPayBankCodeAll"]:checked').val();
        if(bankSelType == '4') allCode = $('input[name="corpPayBankCodeAll"]:checked').val();
        if($.trim(allCode) == ""){
            alert("请选择银行");
            return false;
        }
        $("#payBankCodeAll").val(bankSelType+"-"+allCode);
    }else{
        var payChannelType = $("#payChannel").val();
        if(($("#payWay").val() != "A")){
            if(payChannelType=="01"){
                if(!($('input[name="personalPayBankCode"]:checked').val())){
                    alert("请选择银行");
                    return false;
                }
            }else if(payChannelType=="51"){
                if(!($('input[name="corpPayBankCode"]:checked').val())){
                    alert("请选择银行");
                    return false;
                }
            }
        }
    }
    $("#"+btnId).attr("disabled","disabled");
	payInMoneyPwdCtl("1");
	$("#bankPayForm").submit();
};